package cn.com.utt.unms.mapper;

import java.util.Collection;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface WirelessNetworkMapper {
	
	@Insert({"<script>",
	    "insert into `wireless_network`(network_id,wireless_id) values", 
	      "<foreach item='wirelessId' index='index' collection='wirelessIds' separator=','>",
		      "(#{networkId},#{wirelessId})",
	      "</foreach>",
	    "</script>"})
	void save(@Param("networkId")long networkId, @Param("wirelessIds")List<Long> wirelessIds);
	
	@Delete({"<script>",
	    "delete ", 
	    "FROM `wireless_network`",
	    "WHERE ", 
	    "network_id IN", 
	      "<foreach item='item' index='index' collection='networkIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	void deleteByNetworkIds(@Param("networkIds")List<Long> networkIds);
	
	@Delete({"<script>",
	    "delete ", 
	    "FROM `wireless_network`",
	    "WHERE ", 
	    "wireless_id IN", 
	      "<foreach item='item' index='index' collection='wirelessIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	void deleteByWirelessId(@Param("wirelessIds")List<Long> wirelessIds);
	
	@Select({"<script>",
	    "SELECT network_id", 
	    "FROM wireless_network",
	    "WHERE ", 
	    "wireless_id IN", 
	      "<foreach item='item' index='index' collection='wirelessIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	List<Long> queryNetworkIdsByWirelessIds(@Param("wirelessIds")Collection<Long> wirelessIds);
	
	@Select({"<script>",
	    "SELECT wireless_id", 
	    "FROM wireless_network",
	    "WHERE ", 
	    "network_id IN", 
	      "<foreach item='item' index='index' collection='networkIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	List<Long> queryWirelessIdsByNetworkIds(@Param("networkIds")Collection<Long> networkIds);
	
}
